<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(nums) {
      let freq = {};
      let need = {};
      for (let num of nums) {
        freq[num] = (freq[num] || 0) + 1;
      }
      for (let num of nums) {
        if (freq[num] === 0) continue;
        if (need[num] > 0) {
          need[num]--; need[num + 1] = (need[num + 1] || 0) + 1;
        } else if (freq[num + 1] > 0 && freq[num + 2] > 0) {
          freq[num + 1]--; freq[num + 2]--; need[num + 3] = (need[num + 3] || 0) + 1;
        } else return false;
        freq[num]--;
      }
      return true;
    }
    console.log(arr([1, 2, 3, 3, 4, 5]));
  </script>
</body>

</html>